home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / screen / formlf.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  2.6 KB  |  96 lines

  1. ;void  format_left(strg,distance,color);
  2. ;  unsigned char  *strg,color;
  3. ;  unsigned short  distance;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _video_buffer:word
  7.     EXTRN  _video_page:byte
  8.     EXTRN  _snow_protect:byte
  9.  
  10. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  11.     ASSUME CS:_TEXT
  12.     PUBLIC _format_left
  13. _format_left proc near
  14.     cld            ;set direction flag
  15.     push bp            ;
  16.     mov  bp,sp        ;set stack frame
  17.     push di            ;
  18.     push si            ;
  19.     cmp  _memory_model,0    ;near or far?
  20.     jle  begin        ;jump if near
  21.     inc  bp            ;else add 2 to BP
  22.     inc  bp            ;
  23. begin:    mov  bh,_video_page    ;get BIOS page
  24.     mov  ax,_video_buffer    ;fetch _video_buffer
  25.     mov  es,ax        ;move to ES
  26.     push ds            ;save DS
  27.     mov  ah,3        ;BIOS call for curs pos
  28.     int  10h        ;DH-DL cursor row-col
  29.     mov  ax,160        ;bytes per row
  30.     mul  dh            ;times rows
  31.     sub  cx,cx        ;clear CX
  32.     mov  cl,dl        ;cols to CX
  33.     shl  cl,1        ;double for attributes
  34.     add  ax,cx        ;add to row offset
  35.     mov  di,ax        ;place offset in DI
  36.     mov  bl,_snow_protect    ;fetch _snow_protect
  37.     cmp  _memory_model,2    ;data near or far?
  38.     jb   L0            ;jump if near
  39.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  40.     inc  bp            ;add 2 to BP since dword ptr    
  41.     inc  bp            ;
  42.     jmp  short L00        ;
  43. L0:    mov  si,[bp+4]        ;near case
  44. L00:    mov  byte ptr[bp+4],bl  ;keep _snow_protect
  45.     cmp  byte ptr[si],0    ;test for null string
  46.     je   L6            ;quit if null
  47.     push dx            ;save cursor values
  48.     push bx            ;save video page
  49.     mov  bh,[bp+8]        ;attribute to BH
  50. L1:    mov  bl,[si]        ;get a char
  51.     cmp  bl,0        ;test for end of string
  52.     je   L5            ;
  53.     cmp  byte ptr[bp+4],0    ;protect against snow?
  54.     je   L4            ;jump if not
  55.     mov  dx,3dah        ;status byte address
  56. L2:    in   al,dx        ;get status byte
  57.     test al,1        ;test bit
  58.     jnz  L2            ;loop till 0
  59.     cli            ;disable interrupts
  60. L3:    in   al,dx        ;get status byte
  61.     test al,1        ;test bit
  62.     jz   L3            ;loop till 1
  63. L4:    mov  ax,bx        ;get char-attribute
  64.     stosw            ;write it
  65.     inc  si            ;inc Strg ptr
  66.     jmp  short L1        ;loop
  67. L5:    sti            ;reenable interrupts
  68.     pop  bx            ;video page back to BH
  69.     pop  dx            ;restore cursor values
  70. L6:    mov  cx,[bp+6]        ;get new cursor offset
  71.     test cx,8000h        ;negative?
  72.     jz   L7            ;jump if not
  73.     neg  CX            ;make positive
  74.     add  dh,cl        ;add to row offset
  75.     cmp  dh,24        ;bottom of screen?
  76.     jb   L8            ;jump if not
  77.     mov  dh,24        ;else edge of screen
  78.     jmp  short L8        ;to set cursor
  79. L7:    add  dl,cl        ;add to col offset
  80.     cmp  dl,79        ;off screen?
  81.     jb   L8            ;jump if not
  82.     mov  dl,79        ;else edge of screen
  83. L8:    mov  ah,2        ;BIOS func to set curs
  84.     int  10h        ;set new cursor pos
  85.     pop  ds            ;
  86.     pop  si            ;
  87.     pop  di            ;
  88.     pop  bp            ;
  89.     cmp  _memory_model,0    ;quit
  90.     jle  quit        ;
  91.     db   0CBh        ;RET far
  92. quit:    ret            ;RET near
  93. _format_left endp
  94. _TEXT    ENDS
  95.     END
  96.